'''
@author: pnuzhnyi
'''

from shop.models import item
from django.core.exceptions import ObjectDoesNotExist

class shop_repository():
    def __init__(self):
        pass
    
    def get_item_by_id(self, item_id):
        try:
            return item.objects.get(id=item_id)
        except ObjectDoesNotExist:
            return None
        
    def get_items_for_sale(self):
        items = item.objects.all()
        r=[]
        categories = ["boards","wetsuits","misc"] 
        for c in categories: r.append({"category":c.capitalize(),"items":items.filter(category=c)})
        return r
        
        